package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")//登录
    @ResponseBody
    public Map<String, Object> index(String phone, String password){

        String user = userService.loginAdmin(phone,password);
        Map<String, Object> map = ReturnMap.Returncode(user);
        return map;
    }


    @RequestMapping("/getAllUser")//得到所有用户
    @ResponseBody
    private Map<String, Object> getAllUser() {

        List<User> users =  userService.getAllUser();
        Map<String, Object> map = ReturnMap.ReturnMapS(users);
        return map;

    }

    @RequestMapping("/setpassword")//重置密码
    @ResponseBody
    private Map<String, Object> setpassword(String password,int id) {

        boolean users =  userService.setpassword(password,id);
        Map<String, Object> map = ReturnMap.ReturnMapS(users);
        return map;
    }
    @RequestMapping("/delectUser")//重置密码
    @ResponseBody
    private Map<String, Object> delectUser(int id) {

        boolean users =  userService.delectUser(id);
        Map<String, Object> map = ReturnMap.ReturnMapS(users);
        return map;
    }


}
